<?php
if ( !defined( "IN_UCHOME" ) ) exit( "Access Denied" );
$id = intval($_GET['id']);
$do = in_array($_GET['do'], array('send', 'show')) ? $_GET['do'] : 'send';
require('class.show.php');
$show = new show;
$data = $show->get_data($id);
if(empty($data)) showmessage('你要查看的活动已经不存在了', 'action.php?ac=index', 2);


class invite extends action
{
	function check_invite($id, $email)
	{
		$email = addslashes($email);
		return $this->query_one("select * from ".tname('app_action_invite_site')." where id = '{$id}' and email = '{$email}' ");
	}
}

switch($do){
	case 'send':
		checklogin();
		if($data['uid'] != $uid) showmessage('只有活动的发起者才能使用站外邀请', 'action.php?ac=show&id='.$id, 2);
		$op = in_array($_GET['op'], array('index', 'dump', 'email')) ? $_GET['op'] : 'index';
		$type = $_GET['type'];
		realname_get();
		include_once( template( "action/view/invite" ) );
	break;

	case 'show':
		if($uid > 0 && $uid == $data['uid']) showmessage("实在太奇怪了，怎么有人自己邀请自己呢？","action.php?ac=show&id=".$id, 3);
		if($uid > 0 && $show->check_user($data['id'])) showmessage("你已经加入活动，并通过审核了。系统将跳转到该活动的展示页面","action.php?ac=show&id=".$id, 3);
		$email = urldecode($_GET['email']);
		$hash = $_GET['hash'];
		$invite = new invite;
		$temp = $invite->check_invite($id, $email);
		if(empty($temp) || substr(md5($id . $email . $temp['code']) , 0, 10) != $hash || $temp['status'] != 0){
			showmessage("很抱歉，你的邀请已经过期了","action.php?ac=show&id=".$id, 3);
		}
		$ref = "action.php?ac=invite&do=show&id={$id}&email=" .urlencode($email). "&hash=" . $hash;
		$reg_link = "do.php?ac=register&refer=" . urlencode($ref);
		$login_link = "do.php?ac=login&refer=" . urlencode($ref);
		include_once( template( "action/view/show" ) );
	break;
}

?>